//
//  RegisterViewController.m
//  huanxin
//
//  Created by 郭亚 on 16/4/28.
//  Copyright © 2016年 郭亚. All rights reserved.
//

#import "RegisterViewController.h"

#import "LoginViewController.h"

#import <EaseMob.h>

@interface RegisterViewController ()

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createView];
}

- (void)createView
{
    _userName = [[UITextField alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width - 20, 40)];
    _userName.layer.borderWidth = 0.5;
    _userName.layer.borderColor = [UIColor orangeColor].CGColor;
    _userName.textAlignment = NSTextAlignmentCenter;
    _userName.placeholder = @"请输入用户名";
    [self.view addSubview: _userName];
    
    _passWord = [[UITextField alloc] initWithFrame:CGRectMake(_userName.frame.origin.x, CGRectGetMaxY(_userName.frame) + 10, _userName.frame.size.width, _userName.frame.size.height)];
    _passWord.layer.borderWidth = 0.5;
    _passWord.layer.borderColor = [UIColor orangeColor].CGColor;
    _passWord.textAlignment = NSTextAlignmentCenter;
    _passWord.placeholder = @"请输入密码";
    [self.view addSubview: _passWord];
    
    
    _registerButton = [[UIButton alloc] initWithFrame:CGRectMake(_passWord.frame.origin.x, CGRectGetMaxY(_passWord.frame) + 10, _passWord.frame.size.width, _passWord.frame.size.height)];
    _registerButton.backgroundColor = [UIColor orangeColor];
    [_registerButton setTitle:@"注册" forState:(UIControlStateNormal)];
    _registerButton.layer.cornerRadius = 5;
    [_registerButton addTarget:self action:@selector(registerButtonClicked) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [self.view addSubview:_registerButton];

}

- (void)registerButtonClicked
{

    [[EaseMob sharedInstance].chatManager asyncRegisterNewAccount:_userName.text password:_passWord.text withCompletion:^(NSString *username, NSString *password, EMError *error) {
        if (error == nil) {
            [self dismissViewControllerAnimated:YES completion:^{
                self.block(username, password);
                
            }];
        }
    } onQueue:dispatch_get_main_queue()];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
